package com.xiaoran;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author xiaoRan
 */
public class UserInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            // 已实现的具体类
            return method.invoke(this, args);
        } else {
            Object rst = null;
            // 接口
            if ("getById".equals(method.getName())) {
                SqlSession sqlSession = new SqlSessionTemplate();
                rst = sqlSession.getById((Integer) args[0]);
            }
            return rst;
        }
    }
}
